|
|
|
|
|
|
|
Figure 22.5
Notice that an active OLE object's File
menu does not automatically appear because
saving the file is up to the programmer. |
|
|
|
|
|
|
|
|
Notice that even though you are using methods of the OLE control to save and load the file, you still have to open the file yourself by using the Open statement. You can test the code by saving the drawing, making some changes to it, and then loading the original drawing back into the control. |
|
|
|
|
|
|
|
|
Creating an Embedded Object at Runtime |
|
|
|
|
|
|
|
|
In the preceding example, you created an embedded Paintbrush picture object at designtime. You can also create an "empty" OLE Container control at designtime and load the embedded object at runtime. |
|
|
|
|
|
|
|
|
To create an empty OLE Container control, just choose Cancel when the Insert Object dialog box appears, or right-click the control and choose Delete Embedded Object if one already exists. |
|
|
|
|
|
|
|
|
Create an embedded object at runtime by using the OLE control's CreateEmbed method. The CreateEmbed method takes two parameters: a source document and the class name of the object. You can leave the source document parameter empty if you want a blank object. The following line of code creates a Paintbrush picture object in an OLE control named OLE1: |
|
|
|
|
|
|
|
|
OLE1.CreateEmbed "","Paint.Picture" |
|
|
|
|
|
|
|
|
Notice that you have to specify the class name to create the object. You can view a list of valid class names by clicking the ellipses ( . . . ) in the Properties window by the Class property of the OLE control. |
|
|
|
|
|
|
|
|
The OLE control is also capable of creating linked objects. A linked object is linked to an external file rather than embedded in your application. When you activate a linked object, the application window appears for editing the object. |
|
|
|
|
|
|
|
|
To create a linked document, you must specify a source document name. For a Paintbrush picture object, you specify the location of a bitmap file, as shown in Figure 22.6. |
|
|
|
|
|